package com.whf.android.jar.net.gson;

import com.blankj.utilcode.util.GsonUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

/**
 * 解析(不知道类型情况)
 *
 * @author qf
 * @version 1.0
 */
public class TypeUtils {

    public static <T> Type getType() {
        return new TypeToken<T>() {
        }.getType();
    }

    public static <T> Type getTypeList() {
        return new TypeToken<List<T>>() {
        }.getType();
    }

    public static <T> T getObject(Object object) {
        final String json = GsonUtils.toJson(object);
        return new Gson().fromJson(json, TypeUtils.getType());
    }

    public static <T> List<T> getObjectList(Object object) {
        final String json = GsonUtils.toJson(object);
        return new Gson().fromJson(json, TypeUtils.getTypeList());
    }

}